package com.example.myapplication1.diyview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 *画线view，主要是用Theme.paint
* */
public class MyDividerCell extends View {

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);


    public MyDividerCell(Context context) {
        super(context);
        paint.setColor(Color.BLACK);
    }

    public MyDividerCell(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint.setColor(Color.BLACK);
    }

    public MyDividerCell(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint.setColor(Color.BLACK);
    }
    int realwidth ;
    int realheight;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);


         realwidth = resolveSize(widthSize,widthMeasureSpec);
         realheight = resolveSize(heightSize,heightMeasureSpec);

        setMeasuredDimension(realwidth,realheight);


    }




    @Override
    protected void onDraw(Canvas canvas) {

        super.onDraw(canvas);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(0,0,realwidth,realheight,paint);


    }
}
